package com.activemypc.app.ui.page

import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.*
import androidx.compose.ui.graphics.*
import androidx.compose.ui.platform.*
import androidx.compose.ui.res.*
import androidx.compose.ui.tooling.preview.*
import androidx.compose.ui.unit.*
import androidx.compose.ui.viewinterop.*
import com.activemypc.app.R
import com.activemypc.app.components.AppWebView
import com.activemypc.app.config.AppConfig
import com.activemypc.app.extension.toEmail
import com.activemypc.app.ui.theme.PrimaryColor

/**
 *
 * @Author mocaris
 * @Date 2025-07-21
 */
@Preview
@Composable
fun MainWebPage() {
    val context = LocalContext.current
    val webView = remember {
        AppWebView(context)
    }
    LaunchedEffect(webView) {
        webView.loadUrl(AppConfig.BASE_URL)
    }
    Scaffold {
        Column(modifier = Modifier.padding(it)) {
            AndroidView(
                modifier = Modifier
                    .fillMaxWidth()
                    .weight(1f),
                factory = { webView })
            CopyRight()
        }
    }

}

@Composable
fun CopyRight() {
    val context = LocalContext.current
    Column(
        modifier = Modifier
            .fillMaxWidth()
            .background(color = Color.White)
            .padding(vertical = 10.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(5.dp)
    ) {
        Button(
            modifier = Modifier
                .wrapContentWidth(),
            colors = ButtonDefaults.buttonColors()
                .copy(containerColor = PrimaryColor, contentColor = Color.White),
            shape = CircleShape, onClick = {
                // open email
                context.toEmail(email = AppConfig.EMAIL)
            }) {
            Image(
                modifier = Modifier.height(14.dp),
                painter = painterResource(android.R.drawable.ic_dialog_email),
                contentDescription = null
            )
            Spacer(modifier = Modifier.width(5.dp))
            Text(text = stringResource(R.string.after_sales))
        }
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.spacedBy(
                10.dp,
                alignment = Alignment.CenterHorizontally
            )
        ) {
//            Text(
//                text = "TPV",
//                style = MaterialTheme.typography.bodyMedium.copy(color = PrimaryColor),
//            )
            Text(
                text = stringResource(R.string.main_copy_right),
                style = MaterialTheme.typography.bodyMedium.copy(color = Color.Gray),
            )

        }
    }
}